// pages/News/alreadyOrder/alreadyOrder.js
var businessLogic = require('../../../utils/NetWork/Model/NewsbusinessLogic.js')
var WxParse = require('../../../utils/Component/wxParse/wxParse.js');
var common = require('../../../utils/common.js')
var orgid = common.getStorageSync("orgid")
var userid = common.getStorageSync("userid")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Icon: false,
    add: true,
    content:[],
    content2:[],
    content3:[]
  },
  changeIcon:function(){
    var that = this;
    that.setData({
      Icon: !that.data.Icon,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var orgid = common.getStorageSync("orgid")
    var userid = common.getStorageSync("userid")
    this.setData({
      orgid: orgid,
      userid: userid
    });
    var ryid = options.id;
    this.order(ryid)
    this.order2(ryid)
  },
  //2.2.3查询订阅频道
  order: function (ryid) {
    // 第二步 传参
    let params = {"id":ryid, "orgid": this.data.orgid, "userid": this.data.userid}
    //第三步 调用接口
    businessLogic.ChannelInfo(params, (res) => {
      //第五步 把获取的值，传入data
      this.setData({
        content: res
      });
      var article = res.Introduction;
      var that = this;
      WxParse.wxParse('article', 'html', article, that, 5);
    });

  },
  //2.2.4查询人员是否订阅
  order2: function (ryid) {
    // 第二步 传参
    let params = { "page": 1, "num":1000, "orgid": this.data.orgid, "userid": this.data.userid, "searchField": "channel,people", "searchValue": "" + ryid +","+this.data.userid+""}
    //第三步 调用接口
    businessLogic.PeoTakeList(params, (res) => {
      //第五步 把获取的值，传入data
      this.setData({
        content2: res,
      });
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  },
  //2.2.5人员取消订阅
  orderListquxiao: function () {
    //跳转
    let params = { "ids":this.data.content2[0].id }
    //第三步 调用接口
     businessLogic.PeoTakeDele(params, (res) => {
    });
    var that = this;
    wx.navigateBack({
      delta: 3
    });  
   
     
  },
  orderList2: function () {
    //2.2.6人员订阅
    let InfoJson = '{ "userid": "'+this.data.userid+'", "orgid": "'+this.data.orgid+'", "people": "'+this.data.userid+'", "channel": "'+this.data.content.id+'", "school":"' +this.data.content.school+'" }'
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "InfoJson": InfoJson }
    //第三步 调用接口
    businessLogic.PeoTakeUpdate(params, (res) => {
      //第五步 把获取的值，传入data
      this.setData({
        content3: res
      });
    });
       wx.navigateBack({
      delta: 3
    }); 
    
  }
})